package gwtmodule1.client.gui.admin;

import gwtmodule1.client.gui.utils.DekoTable;
import gwtmodule1.client.gui.utils.FrameClient;
import gwtmodule1.client.gui.utils.FrameProvider;
import gwtmodule1.client.gui.utils.SwitchPage;
import gwtmodule1.client.gui.utils.Title;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class PageListAccounts extends VerticalPanel implements FrameClient {

	private PageEditAccount pageEditAccount = new PageEditAccount();

	public class AccountTable extends DekoTable {
		public AccountTable() {
			super();
			Button add = new Button("add");
			add.addClickListener(new SwitchPage(provider, pageEditAccount,
					new Integer(0)));
			addTitle("Login");
			addTitle("Firstname");
			addTitle("Lastname");
			addTitle("");
			addTitleWidget(add);
		}

		public void addItem(int id, String login, String first, String last) {
			Hyperlink edit = new Hyperlink("edit", "EditAccount" + id);
			edit.addClickListener(new SwitchPage(provider, pageEditAccount,
					new Integer(id)));
			AddRow r = addRow();
			r.add(login);
			r.add(first);
			r.add(last);
			r.add(edit);
			r.add(new Button("delete"));
		}
	}

	private FrameProvider provider;

	private Widget createTable() {
		AccountTable table = new AccountTable();
		table.addItem(1, "god", "Bruce", "Allmighty");
		table.addItem(2, "peter", "Peter", "Meyer");
		table.addItem(3, "dennis", "Dennis", "Petersen");
		return table;
	}

	public PageListAccounts(FrameProvider provider) {
		this.provider = provider;
		add(new Title("Administrate Accounts"));
		add(createTable());
	}

	public void onShow(Object param) {
	}

}
